package shajie.shajun.mmhf;

import android.app.Activity;
import android.app.Application;
import android.content.Context;

import com.imnjh.imagepicker.PickerConfig;
import com.imnjh.imagepicker.SImagePicker;

import java.util.ArrayList;
import java.util.List;

import Util.GlideImageLoader;


/**
 * Created by admin on 2018/2/2.
 */

public class MyApplication extends Application {
    private List<Activity> activityLists;
    //private ApplicationLike tinkerApplicationLike;

    @Override
    public void onCreate() {
        super.onCreate();
                //将我们自己的MyApplication中的所有逻辑放在这里，例如初始化一些第三方
        activityLists=new ArrayList<>();
        Public_Data.context=getApplicationContext();
///**
// * 初始化日志工具
// */
     //   MultiDex.install(this);
//        Logger.addLogAdapter(new AndroidLogAdapter());
//        //TODO 集成：1.4、初始化数据服务SDK、初始化设备信息并启动推送服务
 /**       tinkerApplicationLike = TinkerPatchApplicationLike.getTinkerPatchApplicationLike();

        // 初始化TinkerPatch SDK, 更多配置可参照API章节中的,初始化SDK
        TinkerPatch.init(tinkerApplicationLike)
                .reflectPatchLibrary()
                .fetchPatchUpdate(true)
                // 强制更新
                .setPatchRollbackOnScreenOff(true)
                .setPatchRestartOnSrceenOff(true)
                .setFetchPatchIntervalByHours(3);

        // 每隔3个小时(通过setFetchPatchIntervalByHours设置)去访问后台时候有更新,
        通过handler实现轮训的效果
        TinkerPatch.with().fetchPatchUpdateAndPollWithInterval();*/
        // 启动推送服务
//        x.Ext.init(this);
//        x.Ext.setDebug(false); //是否输出debug日志，开启debug会影响性能。
        SImagePicker.init(new PickerConfig.Builder().setAppContext(getApplicationContext())
                .setImageLoader(new GlideImageLoader(MyApplication.getAppContext()))
                .setToolbaseColor(getApplicationContext().getResources().getColor(R.color.blackgray))
                .build());
    }
    public static Context getAppContext() {
        return  Public_Data.context;
    }
    public void addActivity(Activity activity){
        if (!activityLists.contains(activity))
            activityLists.add(activity);
    }
    public void removeActivity(Activity activity){
        if (activityLists.contains(activity))
            activityLists.remove(activity);
    }
    public void removeAllActivity(){
        for (Activity activity :
                activityLists) {
            activity.finish();
        }
    }
}
